package com.wealth.lottery.util;

import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import com.wealth.lottery.vo.GiftRandom;
public class RandomLotteryNum {
public static void main(String[] args) {
		StringBuffer sb =  new StringBuffer();
//		String a = "0,4";
//		String s = "0,4";
//		String d = "0,4";
//		String f = "0,4";
//		String g = "0,4";
//		String h = "0,4";
//		String f ="d,f,g,h,j";
//		String[] ff =f.split(",");
//		for (int i = 0; i < ff.length; i++) {
//			sb.append(ff[i]).append(",");
//		}
//		//sb.append("0").append(",").append("4");
//		System.out.println(sb.toString());
//	
//		int oldRnum =0;
//		List<GiftRandom> gifts = new ArrayList<GiftRandom>();
//		GiftRandom gift1=new GiftRandom(10,1L,"奖品1", 0.1,"");
//		GiftRandom gift2=new GiftRandom(20,2L,"奖品2", 0.2,"");
//		GiftRandom gift3=new GiftRandom(300,3L,"奖品3", 0.3,"");
//		GiftRandom gift4=new GiftRandom(600,4L,"奖品4",15,"");
//		
//		gifts.add(gift1);
//		gifts.add(gift2);
//		gifts.add(gift3);
//		gifts.add(gift4);
//		
//		getlistP(oldRnum,gifts);
//		
//		for (GiftRandom gift : gifts) {
//			System.out.println("随机数-----："+gift.getSbNum());
//		}
		Random random = new Random();
		int num =random.nextInt(4) % (4 + 1);
		System.out.println(num);
	}
	
	/**
	 * 返回  奖品中奖的随机数
	 * @return
	 */
	public static void getlistP(int oldRnum,List<GiftRandom> gifts){
		
		//总的随机数记录
		List<Integer> listnum = new LinkedList<Integer>(); 
		for (int i = 0; i < gifts.size(); i++) {
			StringBuffer sbnum=new StringBuffer();
			
			//每个奖品的区间值
			int iInterval=(int)(100/gifts.get(i).getProbability());
			System.out.println("iInterval="+iInterval);
			for (int j = 0; j < 5; j++) {
				if(j==0 || j==gifts.get(i).getIndex()){
					sbnum.append(getRandomNum(listnum,oldRnum+iInterval*j,oldRnum+iInterval*(j+1)));
				}else{
					sbnum.append(",").append(getRandomNum(listnum,oldRnum+iInterval*j,oldRnum+iInterval*(j+1)));
				}
			}
			
			gifts.get(i).setSbNum(sbnum.toString());
		}
	}
	
	
	/**
	 * 返回  不重复的随机数
	 *  List<Integer> list = new LinkedList<Integer>();  
	 * @return
	 */
	public static int getRandomNum(List<Integer> list,int min,int max){
		Random random = new Random();
		int num = random.nextInt(max) % (max - min + 1) + min;
	    if(!list.contains(String.valueOf(num))) {  
            list.add(num); 
            return num;
        }else{
        	return getRandomNum(list,min,max);
        }
	}

}
